package utn.frsf.cidisi.upcolbpip.interactionprotocols.diagram.edit.parts;

import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.RotatableDecoration;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.swt.graphics.Color;

import utn.frsf.cidisi.upcolbpip.interactionprotocols.diagram.edit.policies.BusinessMessageItemSemanticEditPolicy;

/**
 * @generated
 */
public class BusinessMessageEditPart extends ConnectionNodeEditPart {

	/**
	 * @generated
	 */
	public static final int VISUAL_ID = 4001;

	/**
	 * @generated
	 */
	public BusinessMessageEditPart(View view) {
		super(view);
	}

	/**
	 * @generated
	 */
	protected void createDefaultEditPolicies() {
		super.createDefaultEditPolicies();
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
				new BusinessMessageItemSemanticEditPolicy());
	}

	/**
	 * @generated
	 */
	protected boolean addFixedChild(EditPart childEditPart) {
		if (childEditPart instanceof BusinessMessageNameEditPart) {
			((BusinessMessageNameEditPart) childEditPart)
					.setLabel(getPrimaryShape()
							.getFigureBusinessMessageNameFigure());
			return true;
		}
		return false;
	}

	/**
	 * @generated
	 */
	protected void addChildVisual(EditPart childEditPart, int index) {
		if (addFixedChild(childEditPart)) {
			return;
		}
		super.addChildVisual(childEditPart, -1);
	}

	/**
	 * Creates figure for this edit part.
	 * 
	 * Body of this method does not depend on settings in generation model
	 * so you may safely remove <i>generated</i> tag and modify it.
	 * 
	 * @generated
	 */

	protected Connection createConnectionFigure() {
		return new BusinessMessageFigure();
	}

	/**
	 * @generated
	 */
	public BusinessMessageFigure getPrimaryShape() {
		return (BusinessMessageFigure) getFigure();
	}

	/**
	 * @generated
	 */
	public class BusinessMessageFigure extends PolylineConnectionEx {

		/**
		 * @generated
		 */
		private WrapLabel fFigureBusinessMessageNameFigure;

		/**
		 * @generated
		 */
		public BusinessMessageFigure() {
			this.setLineWidth(2);
			this.setForegroundColor(THIS_FORE);
			this.setBackgroundColor(THIS_BACK);

			createContents();
			setTargetDecoration(createTargetDecoration());
		}

		/**
		 * @generated
		 */
		private void createContents() {

			fFigureBusinessMessageNameFigure = new WrapLabel();
			fFigureBusinessMessageNameFigure.setText("<..>");

			this.add(fFigureBusinessMessageNameFigure);

		}

		/**
		 * @generated
		 */
		private RotatableDecoration createTargetDecoration() {
			PolygonDecoration df = new PolygonDecoration();
			df.setLineWidth(2);
			df.setForegroundColor(DF_FORE);
			df.setBackgroundColor(DF_BACK);
			return df;
		}

		/**
		 * @generated
		 */
		public WrapLabel getFigureBusinessMessageNameFigure() {
			return fFigureBusinessMessageNameFigure;
		}

	}

	/**
	 * @generated
	 */
	static final Color THIS_FORE = new Color(null, 0, 0, 0);

	/**
	 * @generated
	 */
	static final Color THIS_BACK = new Color(null, 0, 0, 0);

	/**
	 * @generated
	 */
	static final Color DF_FORE = new Color(null, 0, 0, 0);

	/**
	 * @generated
	 */
	static final Color DF_BACK = new Color(null, 0, 0, 0);

}
